<template>
  <div class="mobile-page">
    <div
      class="menus"
      :style="{
        background: `${bgColor[0].item}`,
        marginTop: `${cSlider}px`,
      }"
      v-if="bgColor.length > 0"
    >
      <div
        class="item"
        v-for="(item, index) in list"
        :key="index"
        :class="{ on: curIndex == index }"
        :style="{ color: curIndex == index ? activeColor : txtColor }"
      >
        {{ item.name }} <span :style="{ background: activeColor }"></span>
      </div>
      <div class="category" :style="{ color: txtColor }">
        <span class="iconfont-h5 icon-fenlei3"></span>
        分类
      </div>
    </div>
  </div>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import { mapState } from "vuex";
export default {
  name: "nav_bar",
  configName: "c_nav_bar",
  cname: "商品分类",
  icon: "iconshangpinfenlei",
  type: 0, // 0 基础组件 1 营销组件 2工具组件
  defaultName: "tabNav", // 外面匹配名称
  props: {
    index: {
      type: null,
    },
    num: {
      type: null,
    },
  },
  computed: {
    ...mapState("mobildConfig", ["defaultArray"]),
  },
  watch: {
    pageData: {
      handler(nVal, oVal) {
        this.setConfig(nVal);
      },
      deep: true,
    },
    num: {
      handler(nVal, oVal) {
        let data = this.$store.state.mobildConfig.defaultArray[nVal];
        this.setConfig(data);
      },
      deep: true,
    },
    defaultArray: {
      handler(nVal, oVal) {
        let data = this.$store.state.mobildConfig.defaultArray[this.num];
        this.setConfig(data);
      },
      deep: true,
    },
  },
  data() {
    return {
      // 默认初始化数据禁止修改
      defaultConfig: {
        name: "tabNav",
        timestamp: this.num,
        status: {
          title: "开关",
          default: {
            status: false,
          },
        },
        txtColor: {
          title: "文字颜色",
          name: "txtColor",
          default: [
            {
              item: "#282828",
            },
          ],
          color: [
            {
              item: "#282828",
            },
          ],
        },
        activeColor: {
          title: "选中文字颜色",
          name: "txtColor",
          default: [
            {
              item: "#E93323",
            },
          ],
          color: [
            {
              item: "#E93323",
            },
          ],
        },
        bgColor: {
          title: "背景颜色",
          name: "bgColor",
          default: [
            {
              item: "#FFFFFF",
            }
          ],
          color: [
            {
              item: "#FFFFFF",
            }
          ],
        },
        // 页面间距
        mbConfig: {
          title: "页面间距",
          val: 0,
          min: 0,
        },
      },
      list: [
        {
          name: "精选",
        },
        {
          name: "靓丽美妆",
        },
        {
          name: "母婴",
        },
        {
          name: "珠宝饰品",
        },
        {
          name: "男装",
        },
      ],
      curIndex: 0,
      bgColor: [],
      cSlider: 0,
      txtColor: "",
      activeColor: "",
      status:false,
      pageData: {},
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.pageData = this.$store.state.mobildConfig.defaultArray[
        this.num
      ];
      this.setConfig(this.pageData);
    });
  },
  methods: {
    setConfig(data) {
      if (!data) return;
      if(data.mbConfig){
        this.bgColor = data.bgColor.color;
        this.cSlider = data.mbConfig.val;
        this.txtColor = data.txtColor.color[0].item;
        this.activeColor = data.activeColor.color[0].item;
        
      }
    },
  },
};
</script>

<style scoped lang="scss">
.menus {
  display: flex;
  align-items: center;
  width: 100%;
  height: 46px;
  cursor: pointer;
  background: linear-gradient(90deg, #F62C2C 0%, #F96E29 100%);
  position: relative;
  // padding-right: 50px;
  .category{
    // position: absolute;
    // right: 0;
    // top: 0;
    // line-height: 46px;
    flex: 1;
    color: #282828;
  }
  .item {
    position: relative;
    flex: 1;
    text-align: center;
    color: #282828;

    &.on span {
      display: block;
      position: absolute;
      left: 50%;
      bottom: -5px;
      width: 16px;
      height: 2px;
      transform: translateX(-50%);
      background: #fff;
    }
  }
}
</style>
